﻿using System;
using System.Runtime.Serialization;


namespace GShare1._0
{
    [Serializable()]
    public class ClientInfo : ISerializable
    {
        public string UserName { get; set; }
        public DateTime ConnectionTime { get; set; }
        public string IpAddress { get; set; }

        //Default constructor
        public ClientInfo()
        {
            ConnectionTime = DateTime.Now;
            IpAddress = null;
            UserName = null;
        }

        //Deserialization Ctor
        public ClientInfo(SerializationInfo info, StreamingContext ctxt)
        {
            //Get the values from info and assign them to the appropriate properties
            ConnectionTime = (DateTime)info.GetValue("ConnectionTime", typeof(DateTime));
            IpAddress = (String)info.GetValue("IpAddress", typeof(string));
            UserName = (String)info.GetValue("UserName", typeof(string));
        }

        //Serialization function.
        public virtual void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            //You can use any custom name for your name-value pair. But make sure you
            info.AddValue("ConnectionTime", ConnectionTime);
            info.AddValue("IpAddress", IpAddress);
            info.AddValue("UserName", UserName);
        }
    }
}
